﻿using System;
using System.Drawing;

namespace Sustainalytics.ReportGenerator.BL
{
    public class IncidentsChartTemplate : Dundas.Charting.WinControl.Chart
    {
        public IncidentsChartTemplate(int width, int height)
        {
            var axisXMinimum = DateTime.Now.AddMonths(-36).ToOADate();
            var axisXMaximum = DateTime.Now.ToOADate();

            Palette = Dundas.Charting.WinControl.ChartColorPalette.Dundas;
            Size = new Size(width, height);
            BackGradientEndColor = Color.Transparent;
            BorderLineColor = Color.Transparent;
            BorderLineWidth = 0;
            AlwaysRecreateHotregions = true;

            using (Font calibri10RegularFont = new Font("Calibri", 10, FontStyle.Regular, GraphicsUnit.Point, 1, false),
                        calibri14RegularFont = new Font("Calibri", 14, FontStyle.Regular, GraphicsUnit.Point, 1, false),
                        calibri14BoldFont = new Font("Calibri", 14, FontStyle.Bold, GraphicsUnit.Point, 1, false))
            {
                var chartArea = new Dundas.Charting.WinControl.ChartArea
                {
                    BackColor = Color.Transparent,
                    BackGradientEndColor = Color.Transparent,
                    ShadowColor = Color.Transparent,
                    BorderColor = Color.Transparent,
                    BorderStyle = Dundas.Charting.WinControl.ChartDashStyle.Solid,
                    Name = "ChartArea",
                    Position =
                    {
                        Auto = false,
                        X = 0,
                        Y = 0,
                        Width = 100,
                        Height = 100
                    },
                    InnerPlotPosition =
                    {
                        Auto = true, 
                    },

                    AxisY =
                    {
                        LineWidth = 2,
                        LineColor = Color.Black,
                        LabelsAutoFit = true,
                        LabelsAutoFitMinFontSize = 10,
                        StartFromZero = true,
                        Minimum = 0,
                        Maximum = 10,
                        MajorGrid =
                        {
                            Enabled = false,
                            Interval = 2,
                            IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                            LineColor = Color.FromArgb(64, 64, 64, 64)
                        },
                        MajorTickMark =
                        {
                            Enabled = false,
                            Interval = 2,
                            IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                            Style = Dundas.Charting.WinControl.TickMarkStyle.Outside,
                            LineColor = Color.Black,
                            Size = 0.5f
                        },
                        LabelStyle =
                        {
                            Enabled = true,
                            Format = "N0",
                            Interval = 2,
                            IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                            Font = calibri14RegularFont,
                            FontColor = Color.Black,
                        }
                    },
                    AxisX =
                    {
                        LineColor = Color.Black,
                        LineWidth = 2,
                        LabelsAutoFit = true,
                        TitleFont = calibri10RegularFont,
                        StartFromZero = false,
                        Minimum = axisXMinimum,
                        Maximum = axisXMaximum,
                        MajorGrid =
                        {
                            Enabled = false,
                            Interval = 1,
                            IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                            LineColor = Color.FromArgb(64, 64, 64, 64)
                        },
                        MajorTickMark =
                        {
                            Enabled = true,
                            Interval = 1,
                            IntervalOffsetType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                            IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                            Style = Dundas.Charting.WinControl.TickMarkStyle.Inside,
                            LineColor = Color.Black,
                            LineWidth = 2,
                            Size = 5f
                        },
                        LabelStyle =
                        {
                            Enabled = true,
                            Interval = 1,
                            IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                            IntervalOffset = 0.5,
                            IntervalOffsetType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                            Format = "yyyy",
                            Font = calibri14BoldFont,
                            FontColor = Color.Black
                        }
                    }
                };
                ChartAreas.Add(chartArea);

                //Create a new Series and add it to the Series Collection

                var series1Series = new Dundas.Charting.WinControl.Series
                {
                    ChartArea = "ChartArea",
                    Type = Dundas.Charting.WinControl.SeriesChartType.Point,
                    MarkerStyle = Dundas.Charting.WinControl.MarkerStyle.Circle,
                    MarkerColor = Color.Black,
                    MarkerBorderColor = Color.Black,
                    MarkerBorderWidth = 1,
                    MarkerSize = 15,
                    CustomAttributes = "PointWidth=1.0, ColumnLabelStyle=Horizontal, DrawingStyle=Default, LabelStyle=Auto, DrawSideBySide=Auto",
                    Name = "Series1",
                    XValueType = Dundas.Charting.WinControl.ChartValueTypes.DateTime,
                    YValueType = Dundas.Charting.WinControl.ChartValueTypes.Double,
                    YValuesPerPoint = 2,
                    ShadowOffset = 0,
                    ShowLabelAsValue = false,
                    Font = calibri10RegularFont,
                    ShowInLegend = false,
                    LegendText = "Series1"
                };
                Series.Add(series1Series);

                var series2Series = new Dundas.Charting.WinControl.Series
                {
                    ChartArea = "ChartArea",
                    Type = Dundas.Charting.WinControl.SeriesChartType.Point,
                    MarkerStyle = Dundas.Charting.WinControl.MarkerStyle.Circle,
                    MarkerColor = Color.Transparent,
                    MarkerBorderColor = Color.FromArgb(255, 125, 23, 4),
                    MarkerBorderWidth = 3,
                    MarkerSize = 25,
                    CustomAttributes = "PointWidth=1.0, ColumnLabelStyle=Horizontal, DrawingStyle=Default, LabelStyle=Auto, DrawSideBySide=Auto",
                    Name = "Series2",
                    XValueType = Dundas.Charting.WinControl.ChartValueTypes.DateTime,
                    YValueType = Dundas.Charting.WinControl.ChartValueTypes.Double,
                    YValuesPerPoint = 2,
                    ShadowOffset = 0,
                    ShowLabelAsValue = false,
                    Font = calibri10RegularFont,
                    ShowInLegend = false,
                    LegendText = "Series2"
                };
                Series.Add(series2Series);
            }
        }
    }
}
